home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / so91.lha / Scan / ListPattern.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-23  |  2.4 KB  |  89 lines

  1. ;/* ListPattern.c - AmigaMail MatchFirst()/MatchNext() example.
  2. lc -cfis -v -d0 -b0 -j73 ListPattern.c
  3. blink from ListPattern.o to ListPattern lib lib:amiga.lib ;if you don't have pragmas
  4. quit
  5.  */
  6. /* (c)  Copyright 1991 Commodore-Amiga, Inc.   All rights reserved.
  7. The information contained herein is subject to change without notice,
  8. and is provided "as is" without warranty of any kind, either expressed
  9. or implied.  The entire risk as to the use of this information is
  10. assumed by the user.
  11. */
  12.  
  13. #include <exec/memory.h>
  14. #include <dos/dosextens.h>
  15. #include <dos/rdargs.h>
  16. #include <clib/exec_protos.h>
  17. #include <clib/dos_protos.h>
  18.  
  19. /* undef PRAGMAS if you don't have them */
  20. #define PRAGMAS
  21. #undef PRAGMAS
  22. #ifdef PRAGMAS
  23. #include <pragmas/exec_pragmas.h>
  24. #include <pragmas/dos_pragmas.h>
  25. #else
  26.  
  27. struct ExecBase *SysBase;
  28. struct DosLibrary *DOSBase;
  29. #endif
  30.  
  31. VOID            main(VOID);
  32. UWORD           StrLen(UBYTE *);
  33.  
  34. VOID
  35. main(VOID)
  36. {
  37.  
  38. #ifdef PRAGMAS
  39.     struct DosLibrary *DOSBase;
  40. #endif
  41.  
  42.     struct RDArgs  *readargs;
  43.     LONG            rargs[1];
  44.     LONG            vargs[4];
  45.     UBYTE          *pattern;
  46.     struct AnchorPath *anchorpath;
  47.     LONG            error;
  48.  
  49. #ifndef PRAGMAS
  50.     /* set up SysBase */
  51.     SysBase = (*((struct Library **) 4));
  52. #endif
  53.  
  54.     /* Fail silently if < 37 */
  55.     if (DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37))
  56.     {
  57.         /* See the DOS Autodocs for more information about ReadArgs() */
  58.         if (readargs = ReadArgs("PATTERN/A", rargs, NULL))
  59.         {
  60.             pattern = (UBYTE *) rargs[0];
  61.             if (anchorpath = AllocMem(sizeof(struct AnchorPath) + 512, MEMF_CLEAR))
  62.             {
  63.                 anchorpath->ap_Strlen = 512;
  64.                 anchorpath->ap_BreakBits = SIGBREAKF_CTRL_C;
  65.  
  66.                 if ((error = MatchFirst(pattern, anchorpath)) == 0)
  67.                 {
  68.                     do
  69.                     {
  70.                         vargs[0] = (LONG) anchorpath->ap_Buf;
  71.                         VFPrintf(Output(), "%s\n", vargs);
  72.                     } while ((error = MatchNext(anchorpath)) == 0);
  73.                 }
  74.  
  75.                 MatchEnd(anchorpath);
  76.  
  77.                 if (error != ERROR_NO_MORE_ENTRIES)
  78.                     PrintFault(error, NULL);
  79.  
  80.                 FreeMem(anchorpath, sizeof(struct AnchorPath) + 512);
  81.             }
  82.             FreeArgs(readargs);
  83.         }
  84.         else
  85.             PrintFault(IoErr(), NULL);
  86.         CloseLibrary((struct Library *) DOSBase);
  87.     }
  88. }
  89.